import java.util.Scanner;


public class Heap {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		
		int size = 1;
		
		while(size <= n){
			size *= 2;
		}
		size *=2;
		
		int[] a = new int[size];
		for (int i = 0; i < n; i++) {
			a[n-1+i]= sc.nextInt(); 
		}
		
		for (int i = n-2; i >= 0; i--) {
			int left = 2*i +1;
			int right = 2*i +2;
			
			a[i]= a[left] > a[right] ? a[left] : a[right]; 
			
		}
		
		System.out.println(a[0]);

	}

}
